package com.person.hold.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.person.commons.utils.DAO;
import com.person.commons.utils.FlipPageInfo;
import com.person.dic.model.Dic;
import com.person.hold.model.Hold;
import com.person.hold.service.HoldService;
import com.person.title.model.TitleFunc;

public class HoldServiceImpl implements HoldService{
	
	private DAO dao;
	
	public DAO getDao(){
		return dao;
	}
	public void setDao(DAO dao){
		this.dao=dao;
	}
	/**
	 * 列出所有的留言记录
	 * @param fpi
	 * @return
	 */
	public FlipPageInfo findAllHoldList(FlipPageInfo fpi){
		
		try{
			return dao.findWithPaging("select t.funcName,h.holdName,h.holdHeader,h.holdFlag,h.holdDate,h.holdIp," +
					"h.holdId from Hold h,TitleFunc t where t.funcId=h.funcId order by h.funcId", fpi);
		}catch(Exception e){
			System.out.println("列出所有的留言出现异常");
		}
		return new FlipPageInfo();
	}
	/**
	 * 列出所有的留言记录
	 * @param fpi
	 * @return
	 */
	public FlipPageInfo findAllHoldList(FlipPageInfo fpi, String isAudit){
		
		try{
			return dao.findWithPaging("select h from Hold h,TitleFunc t where t.funcId=h.funcId and h.holdFlag="+isAudit+"order by h.funcId", fpi);
		}catch(Exception e){
			System.out.println("列出所有的留言出现异常");
		}
		return new FlipPageInfo();
	}
	/**
	 * 通过ID查找Hold对象
	 * @param holdId
	 * @return
	 */
	public Hold findHoldById(String holdId){
		
		try{
			return (Hold) dao.find(Hold.class, holdId);
		}catch(Exception e){
			System.out.println("查找Hold对象出现异常");
		}
		return new Hold();
	}
	/**
	 * 从字典查找出心情状态
	 * @param dicNoParent
	 * @return List<Dic>
	 */
	@SuppressWarnings("unchecked")
	public List<Dic> findHoldFromDic (String dicNoParent){
		
		try{
			return dao.find("from Dic where dicNoParent='"+dicNoParent+"'");
		}catch(Exception e){
			System.out.println("从字典查找出心情状态出现异常");
		}
		return new ArrayList();
	}
	/**
	 * 更新Hold对象
	 * @param hold
	 */
	public void updateHold(Hold hold){
		
		try{
			 dao.update(hold);
		}catch(Exception e){
			System.out.println("更新Hold对象出现异常");
		}
	}
	/**
	 * 根据funcId从栏目功能表TitleFunc查找功能名
	 */
	public TitleFunc findTitleFuncByFuncId(String funcId){
		try{
			return (TitleFunc) dao.find(TitleFunc.class, funcId);
		}catch(Exception e){
			System.out.println("栏目功能表TitleFunc查找功能名出现异常");
		}
		return new TitleFunc();
	}
	/**
	 * 根据funcId查找Hold
	 */
	public List<Hold> findHoldByFuncId(String funcId) {
		return this.dao.find("from Hold where funcId='"+funcId+"' and holdFlag='1'") ;
	}	
	
	/**
	 * 创建留言
	 */
	public void createHold(Hold hold) {
				
		this.dao.save(hold) ;
	}
	public void deleteHold(Hold hold){
		dao.delete(hold);
	}
}